//
//  MySideView.m
//  MM
//
//  Created by 郑渊文 on 5/29/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "MySideView.h"
#import "CommonMacro.h"

@implementation MySideView


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self configSubViews];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (NSArray *)dataSources
{
    if (nil == _dataSources)
    {
        _dataSources = [NSArray array];
    }
    return _dataSources;
}

-(void)configSubViews
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH/2,self.frame.size.height- 114) style:UITableViewStylePlain];
    tableView.backgroundColor = [UIColor clearColor];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.scrollEnabled = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self addSubview:tableView];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataSources count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (nil == cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
//        cell.backgroundColor = [UIColor clearColor];
        [cell.textLabel setTextColor:[UIColor blackColor]];
        [cell.textLabel setFont:[UIFont systemFontOfSize:15.0f]];
    }
    cell.textLabel.text = self.dataSources[indexPath.row];
    
    if ([cell.textLabel.text isEqualToString:@"等待上课"]) {
        cell.textLabel.textColor = [UIColor blueColor];
    }else if([cell.textLabel.text isEqualToString:@"待支付"]) {
        cell.textLabel.textColor = [UIColor orangeColor];
    }else if([cell.textLabel.text isEqualToString:@"上课中"]) {
        cell.textLabel.textColor = [UIColor greenColor];
    }else if([cell.textLabel.text isEqualToString:@"全部"]) {
        cell.textLabel.textColor = [UIColor blackColor];
    }
    else
    {
        cell.textLabel.textColor = [UIColor lightGrayColor];
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.2];
    [animation setType:kCATransitionPush];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [animation setSubtype:kCATransitionFromLeft];
    self.hidden = YES;
    BOOL ifshow =self.hidden;
    [[self layer] addAnimation:animation forKey:@"switch"];


        if (self.mysideblock!=nil) {
        self.mysideblock(_dataSources[indexPath.row]);
    }
    if (self.myifshowBlock!=nil) {
        self.myifshowBlock(ifshow);
    }
}

@end
